import React from 'react';
import PropTypes from 'prop-types';
import { Switch, Route, Redirect, routerRedux } from 'dva/router';
import dynamic from 'dva/dynamic';
import App from 'routes/app';
import { LocaleProvider } from 'antd';
import zh_CN from 'antd/lib/locale-provider/zh_CN';
import 'moment/locale/zh-cn';
const { ConnectedRouter } = routerRedux;

const Routers = function ({ history, app }) {
    const error = dynamic({
        app,
        component: () => import('./routes/error'),
    });
    const routes = [
        {
            path: '/login', // 登录页面
            models: () => [import('./models/login/')],
            component: () => import('./routes/login/'),
        },
        {
            path: '/home', // 工作台
            models: () => [import('./models/dashboard/')],
            component: () => import('./routes/dashboard/'),
        },
        {
            path: '/home_list', // 工作台
            models: () => [import('./models/dashboard/')],
            component: () => import('./routes/dashboard_list/'),
        },
        {
            path: '/System_account_working', // 工作台
            models: () => [import('./models/System_account_working/')],
            component: () => import('./routes/System_account_working/'),
        },
        {
            path: '/organization', // 组织结构
            models: () => [import('./models/organization/')],
            component: () => import('./routes/organization/'),
        },
        {
            path: '/Parameter', // 组织结构
            models: () => [import('./models/organization/')],
            component: () => import('./routes/Parameter/'),
        },
        {
            path: '/Maillist', // 人员通讯录
            models: () => [import('./models/Maillist/')],
            component: () => import('./routes/Maillist/'),
        },
        {
            path: '/user/leave', // 人员离职管理
            models: () => [import('./models/user/leave')],
            component: () => import('./routes/user/leave'),
        },
        {
            path: '/Rehearsalplan', // 演练计划
            models: () => [import('./models/Rehearsalplan/')],
            component: () => import('./routes/Rehearsalplan/'),
        },
        {
            path: '/Learningplan', // 学习计划
            models: () => [import('./models/Learningplan/')],
            component: () => import('./routes/Learningplan/'),
        },
        {
            path: '/Learningplan_list', // 演练资料详情
            models: () => [import('./models/Learningplan/')],
            component: () => import('./routes/Learningplan_list/'),
        },
        {
            path: '/AllEmergencysupplies', // 应急物资信息
            models: () => [import('./models/AllEmergencysupplies/')],
            component: () => import('./routes/AllEmergencysupplies/'),
        },
        {
            path: '/AllEmergencysupplies_list', // 应急物资信息
            models: () => [import('./models/AllEmergencysupplies/')],
            component: () => import('./routes/AllEmergencysupplies_list/'),
        },
        {
            path: '/Emergencysupplies', // 应急物资基本信息
            models: () => [import('./models/Emergencysupplies/')],
            component: () => import('./routes/Emergencysupplies/'),
        },
        {
            path: '/Emergencysupplies_list', // 应急物资基本信息列表
            models: () => [import('./models/Emergencysupplies/')],
            component: () => import('./routes/Emergencysupplies_list/'),
        },
        {
            path: '/Placeofstorage', // 库存地点管理
            models: () => [import('./models/Placeofstorage/')],
            component: () => import('./routes/Placeofstorage/'),
        },
        {
            path: '/Emergencyplan', // 应急预案
            models: () => [import('./models/Emergencyplan/')],
            component: () => import('./routes/Emergencyplan/'),
        },
        {
            path: '/Emergencyplan_list', // 应急预案详情
            models: () => [import('./models/Emergencyplan/')],
            component: () => import('./routes/Emergencyplan_list/'),
        },
        {
            path: '/categorymanagement', // 应急预案详情
            models: () => [import('./models/categorymanagement/')],
            component: () => import('./routes/categorymanagement/'),
        },
        {
            path: '/categorymanagement_list', // 应急预案详情
            models: () => [import('./models/categorymanagement/')],
            component: () => import('./routes/categorymanagement_list/'),
        },
        {
            path: '/management', // 应急预案详情
            models: () => [import('./models/management/')],
            component: () => import('./routes/management/'),
        },
        {
            path: '/Evacuate', // 应急疏散场所管理
            models: () => [import('./models/Evacuate/')],
            component: () => import('./routes/Evacuate/'),
        },
        {
            path: '/Lawlearningfa', // 法规学习
            models: () => [import('./models/Lawlearning/')],
            component: () => import('./routes/Lawlearning/'),
        },
        {
            path: '/Lawlearningying', // 应急科普
            models: () => [import('./models/Lawlearning/')],
            component: () => import('./routes/Lawlearning/'),
        },
        {
            path: '/Lawlearningzai', // 灾难警示
            models: () => [import('./models/Lawlearning/')],
            component: () => import('./routes/Lawlearning/'),
        },
        {
            path: '/Lawlearningan', // 应急预案
            models: () => [import('./models/Lawlearning/')],
            component: () => import('./routes/Lawlearning/'),
        },
        {
            path: '/LawlearninganK', // 应急处置卡
            models: () => [import('./models/Lawlearning/')],
            component: () => import('./routes/Lawlearning/'),
        },
        {
            path: '/production', // 巡检记录
            models: () => [import('./models/Production/')],
            component: () => import('./routes/Production/'),
        },
        {
            path: '/production_list', // 巡检记录详情
            models: () => [import('./models/Production/')],
            component: () => import('./routes/production_list/'),
        },
        {
            path: '/inspection', // 检查项目分类
            models: () => [import('./models/inspection/')],
            component: () => import('./routes/inspection/'),
        },
        {
            path: '/Inspectionproject', // 检查项目
            models: () => [import('./models/Inspectionproject/')],
            component: () => import('./routes/Inspectionproject/'),
        },
        {
            path: '/Inspectionproject_list', // 检查项目详情
            models: () => [import('./models/Inspectionproject/')],
            component: () => import('./routes/Inspectionproject_list/'),
        },
        {
            path: '/Inspectionproject_list_option', // 检查项目详情操作
            models: () => [import('./models/Inspectionproject/')],
            component: () => import('./routes/Inspectionproject/'),
        },
        {
            path: '/checkpoint', // 巡检点
            models: () => [import('./models/checkpoint/')],
            component: () => import('./routes/checkpoint/'),
        },
        {
            path: '/checkpoint_list', // 巡检点详情
            models: () => [import('./models/checkpoint/')],
            component: () => import('./routes/checkpoint_list/'),
        },
        {
            path: '/pointroad', // 巡检路线
            models: () => [import('./models/pointroad/')],
            component: () => import('./routes/pointroad/'),
        },
        {
            path: '/pointroad_list', // 巡检路线详情
            models: () => [import('./models/pointroad/')],
            component: () => import('./routes/pointroad_list/'),
        },
        {
            path: '/ponitplan', // 巡检计划
            models: () => [import('./models/ponitplan/')],
            component: () => import('./routes/ponitplan/'),
        },
        {
            path: '/pointplanVale', // 巡检计划统计分析
            models: () => [import('./models/pointplanVale/')],
            component: () => import('./routes/pointplanVale/'),
        },
        {
            path: '/pointroadVale', // 巡检路线统计分析
            models: () => [import('./models/pointroadVale/')],
            component: () => import('./routes/pointroadVale/'),
        },
        {
            path: '/dutymanagement', // 日程管理
            models: () => [import('./models/dutymanagement/')],
            component: () => import('./routes/dutymanagement/'),
        },
        {
            path: '/System_account', // 系统账户
            models: () => [import('./models/System_account/')],
            component: () => import('./routes/System_account/'),
        },
        {
            path: '/Privilege_management', // 权限管理
            models: () => [import('./models/Privilege_management/')],
            component: () => import('./routes/Privilege_management/'),
        },
        {
            path: '/Materialinspection', // 物资巡查记录统计
            models: () => [import('./models/Materialinspection/')],
            component: () => import('./routes/Materialinspection/'),
        },
        {
            path: '/Privilege_management_list', // 物资巡查记录统计
            models: () => [import('./models/Privilege_management/')],
            component: () => import('./routes/pointroad_list/'),
        },
        {
            path: '/task/exam/forms', // 考试结果
            models: () => [import('./models/task/exam/form')],
            component: () => import('./routes/task/exam/Forms'),
        },
        {
            path: '/task/integral/forms', // 考试结果
            models: () => [import('./models/task/integral/form')],
            component: () => import('./routes/task/integral/Forms'),
        },
    ];

    return (
        <ConnectedRouter history={history}>
            <LocaleProvider locale={zh_CN}>
                <App>
                    <Switch>
                        <Route exact path="/" render={() => (<Redirect to="/login" />)} />
                        {
                            routes.map(({ path, ...dynamics }, key) => (
                                <Route
                                    key={key}
                                    exact
                                    path={path}
                                    component={dynamic({
                                        app,
                                        ...dynamics,
                                    })}
                                />
                            ))
                        }
                        <Route component={error} />
                    </Switch>
                </App>
            </LocaleProvider>
        </ConnectedRouter>
    );
};

Routers.propTypes = {
    history: PropTypes.object,
    app: PropTypes.object,
};

export default Routers;
